#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc ,char *argv[])
{
    int fd = open(argv[1],O_RDWR);   
    
    unsigned short ir,als,ps;
    unsigned char buf[6];
    while(1)
    {
        read(fd,buf,6);
        if(buf[0] & 0X80) 	/* IR_OF位为1,则数据无效 */
            ir = 0;					
        else 				/* 读取IR传感器的数据   		*/
            ir = ((unsigned short)buf[1] << 2) | (buf[0] & 0X03); 			
        
        als = ((unsigned short)buf[3] << 8) | buf[2];	/* 读取ALS传感器的数据 			 */  
        
        if(buf[4] & 0x40)	/* IR_OF位为1,则数据无效 			*/
            ps = 0;    													
        else 				/* 读取PS传感器的数据    */
            ps = ((unsigned short)(buf[5] & 0X3F) << 4) | (buf[4] & 0X0F); 
        printf("ir=%d\tals=%d\tps=%d\r\n",ir,als,ps);
        usleep(10*1000); 
    }
    close(fd);
    return 0;
}